<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>02-数组</title>
</head>
<body>
<script>
  var arr1=[1,2,3,4,5];
  var arr2 = new Array();
  console.log(arr1);
  console.log(arr2);
  console.log(typeof arr1);
  console.log(typeof arr2);
  // 添加元素
  var array=new Array();
  array.push(1,2,3,4,5,6);
  console.log(array.length);
  console.log(array[2]);
  array[2]=300;
  // 遍历数组
  for (let i = 0; i < array.length; i++) {
      console.log(array[i]);
  }
  console.log("----------------------");
  // 添加头部元素
  array.unshift(9,8,7);
  console.log(array);//[9, 8, 7, 1, 2, 300, 4, 5, 6]
  // 删除尾部元素
  array.pop();
  console.log(array);//9,8,7,1,2,300,4,5
  // 删除头部元素
  array.shift();
  console.log(array);//8,7,1,2,300,4,5


  // 添加元素
  array.splice(1,0,800,"zyh");
  console.log(array);//[9, 800, 'zyh', 8, 7, 1, 2, 300, 4, 5, 6]
  // 替换元素
  array.splice(0,1,900);
  console.log(array);//[900, 800, 'zyh', 8, 7, 1, 2, 300, 4, 5, 6]
  // 删除一个或者多个元素
  array.splice(8,3);
  console.log(array);//[900, 800, 'zyh', 8, 7, 1, 2, 300]
  var reverse = array.reverse();
  console.log(reverse);//[300, 2, 1, 7, 8, 'zyh', 800, 900]
</script>
</body>
</html>